package com.djq.project.mq.consumer.publish;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PublishConfig {

    @Bean
    public Queue queue1() {
        return new Queue("publish1", true);
    }

    @Bean
    public Queue queue2() {
        return new Queue("publish2", true);
    }

    //创建一个fanoutExchange交换机
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("publish_exchange");
    }

    //将queueA队列绑定到fanoutExchange交换机上面
    @Bean
    Binding bindingExchangeMessageFanout1(Queue queue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    //将queueB队列绑定到fanoutExchange交换机上面
    @Bean
    Binding bindingExchangeMessageFanout2(Queue queue2, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }

}
